#include <stdio.h>
#include <stdlib.h>
void readFile(FILE *f)
{
    if ((f = fopen("demo.txt", "r")) == NULL)
    {
       exit(1);
    }
    //读字符
    char c;
    int count = 0;
    while ((c = fgetc(f)) != EOF)
    {
        putchar(c);
        count++;
        //       printf("第%d个字符\n",count);
    }
    printf("一共%d个字符\n", count);
    fclose(f);
}

void writeFile(FILE *f)
{
    //写字符
    if ((f = fopen("demo.txt", "a+")) == NULL)
    {
        exit(1);
    }
    char c;
    while ((c = getchar()) != '\n')
    {
        fputc(c, f);
    }
    fclose(f);
}
int main()
{

    FILE *f;
    readFile(f);
    writeFile(f);
    readFile(f);
    return 0;
}